﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace EasyNet.Componets.Core.Extensions
{
    public static class TypeExternsion
    {
        private static object _propertyCacheLockObj = new object();
        private static Dictionary<Type, PropertyInfo[]> _propertyCacheDic = new Dictionary<Type, PropertyInfo[]>();

     
        public static PropertyInfo[] GetPropertyInfoWithCache(this Type type)
        {
            PropertyInfo[] properties;
            lock (_propertyCacheLockObj)
            {
                if (_propertyCacheDic.ContainsKey(type))
                {
                    properties = type.GetProperties();
                }
                else
                {
                    properties = type.GetProperties();
                    try
                    {
                        _propertyCacheDic.Add(type, properties);
                    }
                    catch
                    {

                    }
                }
            }

            return properties;
        }
    }
}
